﻿using Cherry.Agile.Core;
using Cherry.Agile.Enterprise.Entity;
using Cherry.Agile.Enterprise.Services.Interface;
using Cherry.Agile.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cherry.Agile.Enterprise.Services.Security
{
    public class AuthorizationProvider : IAuthorizationProvider
    {
        public User Authorize(ITicket ticket)
        {
            var service = ServiceFactory.GetService<IAuthorizationService>();
            var at = ticket as Cherry.Agile.Security.AccountTicket;
            if (at == null)
                throw new ArgumentNullException("错误的票据");
            //return service.Authorize(at);
            var user = service.GetUser(at);
            //if (user == null)
            //    throw new AuthurizationValidateFailedException(FailedReason.Invalid);
            //if (user.Status == (int)FreezeOrActiveEnum.Freeze)
            //    throw new AuthurizationValidateFailedException(FailedReason.Locked);
            //string pwd = at.Password;
            //if (!ticket.Encrypted)
            //    pwd = user.EntryPassword(pwd);

            //if (user.Password != pwd)
            //    throw new AuthurizationValidateFailedException(FailedReason.PasswordError);
            return user;
        }

        public User GetUser(ITicket identity)
        {
            throw new NotImplementedException();
        }

        public Role[] GetUserRoles(ITicket identity)
        {
            throw new NotImplementedException();
        }

        public Organization[] GetUserOrgs(ITicket identity)
        {
            throw new NotImplementedException();
        }


        Framework.Common.Application[] IAuthorizationProvider.GetApplicationInfos()
        {
            throw new NotImplementedException();
        }
    }
}
